package com.topnav.mc.admin.entity.wrapper;

import com.topnav.mc.admin.entity.param.DeviceChannelParam;
import com.topnav.mc.base.mc.McWrapper;
import org.springframework.util.StringUtils;

public class DeviceChannelWrapper extends McWrapper<DeviceChannelParam> {
    public DeviceChannelWrapper(DeviceChannelParam entity) {
        super(entity);
        if (entity != null){
            if (entity.getId()!=null){this.eq("c.id",entity.getId());}
            if (entity.getDeviceId()!=null){this.eq("c.device_id",entity.getDeviceId());}
            if (entity.getStatus()!=null){this.eq("c.status",entity.getStatus());}
            if (!StringUtils.isEmpty(entity.getChannelCode())){this.like("c.channel_code",entity.getChannelCode());}
            if (!StringUtils.isEmpty(entity.getName())){this.like("c.name",entity.getName());}
            if (!StringUtils.isEmpty(entity.getKeyword())){
                this.and(wrapper -> wrapper.like("c.channel_code", entity.getKeyword())
                        .or().like("c.name", entity.getKeyword())
                );
            }
            this.orderByDesc("c.id");

        }
    }
}
